//<my-matriculator - a simple tool for registering racers in a USAC cyclocross race>
//Copyright (C) <2011>  <Steven Rivers>

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System.ComponentModel;

namespace Registration.Model.Entities
{
    public class Field : INotifyPropertyChanged
    {
        private int _fieldid;
        public int FieldId
        {
            get { return _fieldid; }
            set
            {
                _fieldid = value;
                OnPropertyChanged(new PropertyChangedEventArgs("FieldId"));
            }
        }

        private string _fieldname;
        public string FieldName
        {
            get { return _fieldname; }
            set 
            { 
                _fieldname = value;
                OnPropertyChanged(new PropertyChangedEventArgs("FieldName"));
            }
        }

        private bool _fieldopen;
        public bool FieldOpen
        {
            get { return _fieldopen; }
            set
            {
                _fieldopen = value;
                OnPropertyChanged(new PropertyChangedEventArgs("FieldOpen"));
            }

        }


        private int _nextbib;
        public int NextBib
        {
            get { return _nextbib; }
            set
            {
                _nextbib = value;
                OnPropertyChanged(new PropertyChangedEventArgs("NextBib"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        
        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Field)) return false;
            return Equals((Field) obj);
        }

        public Field(int id, string name, bool open, int next)
        {
            FieldId = id;
            FieldName = name;
            FieldOpen = open;
            NextBib = next;
        }

        public bool Equals(Field other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other._fieldid == _fieldid && Equals(other._fieldname, _fieldname) && other._fieldopen.Equals(_fieldopen) && other._nextbib == _nextbib;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = _fieldid;
                result = (result*397) ^ (_fieldname != null ? _fieldname.GetHashCode() : 0);
                result = (result*397) ^ _fieldopen.GetHashCode();
                result = (result*397) ^ _nextbib;
                return result;
            }
        }
    }
}